<html>
<head><meta charset="utf-8"><title>longjmp interaction with destructors · project-ffi-unwind · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/index.html">project-ffi-unwind</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html">longjmp interaction with destructors</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="179231647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179231647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179231647">(Oct 28 2019 at 13:44)</a>:</h4>
<p>I would just make it UB unless there's actual demand for people relying on longjmp running destructors.</p>



<a name="179231679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179231679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179231679">(Oct 28 2019 at 13:45)</a>:</h4>
<p>What does longjmp do for automatic variables in a frame ?</p>



<a name="179231702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179231702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179231702">(Oct 28 2019 at 13:45)</a>:</h4>
<p>Depending on how its implemented, it semantically either calls <code>mem::drop</code>, or it calls <code>mem::forget</code></p>



<a name="179231704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179231704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179231704">(Oct 28 2019 at 13:45)</a>:</h4>
<p>both are ok</p>



<a name="179231714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179231714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179231714">(Oct 28 2019 at 13:45)</a>:</h4>
<p>and actually safe</p>



<a name="179231812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179231812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179231812">(Oct 28 2019 at 13:46)</a>:</h4>
<p>Only if the code that is being jumped over expects this.</p>



<a name="179231826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179231826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179231826">(Oct 28 2019 at 13:46)</a>:</h4>
<p>the only real issue is that some types have a "Safety" requirement that says "you can't deallocate this type without calling destructors", making <code>forget</code> illegal on them</p>



<a name="179231845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179231845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179231845">(Oct 28 2019 at 13:46)</a>:</h4>
<p>but that's a safety invariant that unsafe code working with these types must upheld</p>



<a name="179231888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179231888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179231888">(Oct 28 2019 at 13:47)</a>:</h4>
<blockquote>
<p>Only if the code that is being jumped over expects thi</p>
</blockquote>
<p>Well yes, but APIs can write arbitrary requirements in the safety clause.</p>



<a name="179231907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179231907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179231907">(Oct 28 2019 at 13:47)</a>:</h4>
<p>I don't think this one is very different from any other pre-condition</p>



<a name="179231977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179231977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179231977">(Oct 28 2019 at 13:48)</a>:</h4>
<p>So... IMO the rules for <code>longjmp</code> follow from the rules of <code>mem::forget</code></p>



<a name="179231982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179231982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179231982">(Oct 28 2019 at 13:48)</a>:</h4>
<p>IMO code should be able to assume that any callbacks either return properly or unwind and run all destructors.</p>



<a name="179232022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232022">(Oct 28 2019 at 13:48)</a>:</h4>
<p>For this types, you can put them in some memory address on the heap, and if you deallocate them with <code>GlobalAlloc::dealloc</code> without running their destructor the behavior is undefined as well</p>



<a name="179232046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232046">(Oct 28 2019 at 13:48)</a>:</h4>
<p>that's "library UB" because the code violates a safety invariant expressed in a library API comment</p>



<a name="179232057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232057">(Oct 28 2019 at 13:49)</a>:</h4>
<p>Because <code>DropGuard</code>s can be used to maintain safety invariants, and currently a lot of code in the wild does this (even code in libstd).</p>



<a name="179232059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232059">(Oct 28 2019 at 13:49)</a>:</h4>
<p>one doesn't need <code>longjmp</code> for that</p>



<a name="179232181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232181">(Oct 28 2019 at 13:50)</a>:</h4>
<p>I don't see a reason to forbid <code>longjmp</code> over frames with destructors that lack safety invariants</p>



<a name="179232207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232207">(Oct 28 2019 at 13:50)</a>:</h4>
<p>it's a perfectly correct thing to do, we'll just be introducing UB to forbid something that has no issues</p>



<a name="179232352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232352">(Oct 28 2019 at 13:52)</a>:</h4>
<p>Also, <code>DropGuard</code> has no issues in safe Rust</p>



<a name="179232379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232379">(Oct 28 2019 at 13:52)</a>:</h4>
<p>Here's an example: <code>slice::sort</code> is unsound if <code>Ord::cmp</code> longjmps without running destructors.</p>



<a name="179232380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232380">(Oct 28 2019 at 13:52)</a>:</h4>
<p>if that frame calls some other unsafe Rust code that violates its safety invariants..</p>



<a name="179232400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232400">(Oct 28 2019 at 13:52)</a>:</h4>
<p>Sure, but then that <code>Ord::cmp</code> implementation is unsound</p>



<a name="179232421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232421">(Oct 28 2019 at 13:52)</a>:</h4>
<p>because it is safe code that calls <code>unsafe</code> code that does not properly encapsulate the unsafety</p>



<a name="179232617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232617">(Oct 28 2019 at 13:54)</a>:</h4>
<p>Maybe i'm miscommunicating: i'm not proposing to make <code>longjmp</code> safe, it would still be <code>unsafe</code> to call,  and the caller needs to make sure that doing that does not result in UB.</p>



<a name="179232682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232682">(Oct 28 2019 at 13:55)</a>:</h4>
<p>There are many types with destructors that can be longjmp'ed without issues, I'd rather not introduce a completely new different kind of UB just for <code>longjmp</code></p>



<a name="179232859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232859">(Oct 28 2019 at 13:56)</a>:</h4>
<p>My point is, <code>slice::sort</code> should be able to assume that <code>Ord::cmp</code> won't longjmp out without running destructors, without having to list it in the safety invariants in the <code>slice::sort</code> docs.</p>



<a name="179232945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232945">(Oct 28 2019 at 13:57)</a>:</h4>
<p>Sure, it can do that</p>



<a name="179232950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232950">(Oct 28 2019 at 13:57)</a>:</h4>
<p><code>Ord::cmp</code> is a safe Rust function</p>



<a name="179232958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179232958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179232958">(Oct 28 2019 at 13:57)</a>:</h4>
<p>those functions cannot <code>longjmp</code></p>



<a name="179233048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233048">(Oct 28 2019 at 13:58)</a>:</h4>
<p>If we allow safe Rust code to <code>longjmp</code>, we would make safe Rust unsound</p>



<a name="179233085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233085">(Oct 28 2019 at 13:58)</a>:</h4>
<p>So we can't do that</p>



<a name="179233096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233096">(Oct 28 2019 at 13:58)</a>:</h4>
<p>Anyways, I feel that unless you have a particular use case for allowing <code>longjmp</code> to skip destructors, we should just make it UB.</p>



<a name="179233110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233110">(Oct 28 2019 at 13:59)</a>:</h4>
<p>The problem is that skipping destructors is ok</p>



<a name="179233118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233118">(Oct 28 2019 at 13:59)</a>:</h4>
<p>in many cases</p>



<a name="179233132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233132">(Oct 28 2019 at 13:59)</a>:</h4>
<p>and there is no <code>longjmp</code> in the Rust spec</p>



<a name="179233138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233138">(Oct 28 2019 at 13:59)</a>:</h4>
<p>so we can't talk about it</p>



<a name="179233178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233178">(Oct 28 2019 at 13:59)</a>:</h4>
<p>So we would be introducing a clause somewhere saying that skipping destructors in safe Rust in certain cases is UB</p>



<a name="179233183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233183">(Oct 28 2019 at 13:59)</a>:</h4>
<p>which already is</p>



<a name="179233246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233246">(Oct 28 2019 at 14:00)</a>:</h4>
<p>but that does not ban <code>longjmp</code></p>



<a name="179233260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233260">(Oct 28 2019 at 14:00)</a>:</h4>
<p>it just ban <code>longjmp</code> from those uses</p>



<a name="179233518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233518">(Oct 28 2019 at 14:03)</a>:</h4>
<p>Best case we maybe we can say that "Unwinding a frame without invoking destructors is UB", but that means that <code>longjmp</code> on MSVC is ok, because it does run destructors there</p>



<a name="179233619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233619">(Oct 28 2019 at 14:04)</a>:</h4>
<p>(assuming you've used <code>#[unwind(allowed)]</code> in all the right places)</p>



<a name="179233630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233630">(Oct 28 2019 at 14:04)</a>:</h4>
<p>sure</p>



<a name="179233657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233657">(Oct 28 2019 at 14:04)</a>:</h4>
<p>otherwise destructors might be optimized away</p>



<a name="179233659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233659">(Oct 28 2019 at 14:04)</a>:</h4>
<p>OK that sounds reasonable to me.</p>



<a name="179233692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233692">(Oct 28 2019 at 14:05)</a>:</h4>
<p>Though I would still prefer outright making skipping destructors UB.</p>



<a name="179233710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233710">(Oct 28 2019 at 14:05)</a>:</h4>
<p>When one thinks of the stack in terms of miri, you have a <code>Vec&lt;Frame&gt;</code> where <code>Frame { vars..: Box&lt;T&gt; }</code> (each automatic variable is its own allocation)</p>



<a name="179233723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233723">(Oct 28 2019 at 14:05)</a>:</h4>
<p>A panic <code>drops</code> a frame, and a <code>longjmp</code> <code>mem::forgets</code> a frame</p>



<a name="179233735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233735">(Oct 28 2019 at 14:05)</a>:</h4>
<p>We already have the rules for both in the language</p>



<a name="179233831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233831">(Oct 28 2019 at 14:06)</a>:</h4>
<p>and, e.g., if you have a <code>Box&lt;Pin&lt;....&gt;&gt;</code> and  you deallocate the <code>Pin</code> without running destructors, you get the exact same of UB that you get if you <code>longjmp</code> over a Frame containing a Pin</p>



<a name="179233873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233873">(Oct 28 2019 at 14:07)</a>:</h4>
<p>So the rules that there is UB for certain longjmps are already there, and they apply to more cases than just the <code>longjmp</code> themselves</p>



<a name="179233951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233951">(Oct 28 2019 at 14:08)</a>:</h4>
<p>So to me not adding an extra rule to forbid <code>longjmp</code>s over frames with destructors  even when that is not really UB of another kind complicates the language for little reason</p>



<a name="179233993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179233993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179233993">(Oct 28 2019 at 14:08)</a>:</h4>
<p>I mean, a <code>longjmp</code> over a <code>Pin</code> isn't "real UB"</p>



<a name="179234033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179234033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179234033">(Oct 28 2019 at 14:09)</a>:</h4>
<p>the UB is when the storage of the <code>Pin</code> is deallocated without running the destructor, and a different thread tries later to do a <code>use-after-free</code></p>



<a name="179234165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179234165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179234165">(Oct 28 2019 at 14:10)</a>:</h4>
<p>but if that does not happen, everything is still "fine" (your program might be non portable or whatever, but it does not have UB)</p>



<a name="179234271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179234271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179234271">(Oct 28 2019 at 14:11)</a>:</h4>
<p>If that does happen, you have a <code>use-after-free</code>, whether that was caused by a <code>longjmp</code>, or a call to <code>Alloc::dealloc</code>, isn't really that different</p>



<a name="179253236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179253236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179253236">(Oct 28 2019 at 17:15)</a>:</h4>
<p>Re: this bit in the PR thread:</p>
<blockquote>
<p>Actually <code>longjmp</code> does run destructors (both C++ and Rust) because it uses a SEH exception to unwind. This was already the case before this PR. However <code>_CxxFrameHandler3</code> specifically ignores <code>longjmp</code> exceptions for <code>catch</code> blocks.</p>
<p>This behavior is documented in MSVC, and is allowed by the C++ standard since it is UB to unwind across frames with destructors.</p>
</blockquote>
<p>Maybe you already knew this, <span class="user-mention" data-user-id="143274">@Amanieu</span> , but what I have been told is that MSVC does not invoke C++ destructors on <code>longjmp</code> unwind, but Clang-targeting-MSVC does.</p>



<a name="179253581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179253581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179253581">(Oct 28 2019 at 17:19)</a>:</h4>
<p><a href="https://docs.microsoft.com/en-us/cpp/cpp/using-setjmp-longjmp?view=vs-2019" target="_blank" title="https://docs.microsoft.com/en-us/cpp/cpp/using-setjmp-longjmp?view=vs-2019">https://docs.microsoft.com/en-us/cpp/cpp/using-setjmp-longjmp?view=vs-2019</a></p>
<blockquote>
<p>If you use an /EH option to compile C++ code, destructors for local objects are called during the stack unwind. However, if you use /EHs or /EHsc to compile, and one of your functions that uses noexcept calls longjmp, then the destructor unwind for that function might not occur, depending on the optimizer state.</p>
</blockquote>



<a name="179253921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179253921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179253921">(Oct 28 2019 at 17:22)</a>:</h4>
<p>Oops. Yes, I've read that, but apparently forgot it.</p>



<a name="179636066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179636066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179636066">(Nov 01 2019 at 15:35)</a>:</h4>
<p>I've (intentionally) withheld from reading this thread</p>



<a name="179636071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179636071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179636071">(Nov 01 2019 at 15:35)</a>:</h4>
<p>I would like to make a request</p>



<a name="179636111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/179636111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#179636111">(Nov 01 2019 at 15:35)</a>:</h4>
<p>could somebody -- <span class="user-mention" data-user-id="132920">@gnzlbg</span>, <span class="user-mention" data-user-id="143274">@Amanieu</span>, <span class="user-mention" data-user-id="120076">@Kyle Strand</span> -- open a PR against the ffi-unwind repo that summarizes how longjmp interacts with destructurs on various tier 1 platforms? (i.e., summarizes what was learned from this thread?)</p>



<a name="180979690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/180979690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#180979690">(Nov 18 2019 at 00:41)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> <span class="user-mention" data-user-id="143274">@Amanieu</span> I started drafting a document as Niko asked: <a href="https://github.com/BatmanAoD/project-ffi-unwind/blob/topic-longjmp-destructors/periodic-summaries/topic-longmp-destructors.md" target="_blank" title="https://github.com/BatmanAoD/project-ffi-unwind/blob/topic-longjmp-destructors/periodic-summaries/topic-longmp-destructors.md">https://github.com/BatmanAoD/project-ffi-unwind/blob/topic-longjmp-destructors/periodic-summaries/topic-longmp-destructors.md</a></p>
<p>I didn't follow the discussion closely, so I would appreicate if one or both of you would "adopt" that branch, make appropriate changes, and open a PR.</p>



<a name="182309272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/182309272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pquux <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#182309272">(Dec 02 2019 at 01:36)</a>:</h4>
<p>Apologies if this is the wrong venue for this: is there some document or comment somewhere which lists the current best practices and/or pitfalls surrounding ffi and longjmp? I understand the general issues, but Im trying to implement something which will likely require ffi interaction with longjmp and there area dizzying amount of relevant threads and comments.</p>



<a name="182309933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/182309933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#182309933">(Dec 02 2019 at 01:56)</a>:</h4>
<p>@pquux The short version is that longjmp over frames with destructors should (for now, possibly indefinitely) be considered UB, but otherwise (e.g. if the only local types in the frames being dropped are <code>Copy</code>) the behavior is well defined.</p>



<a name="182309955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/182309955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#182309955">(Dec 02 2019 at 01:57)</a>:</h4>
<p>Or rather, the behavior is as well-defined as it is in C (e.g. you can have UB if you do weird things like trying to restore a stack context created in a different thread).</p>



<a name="182310731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/182310731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pquux <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#182310731">(Dec 02 2019 at 02:20)</a>:</h4>
<p>Awesome, thank you very much. I imagine you have plenty of actual examples and use cases already, but please feel free to ping me if you need another.</p>



<a name="182311081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/182311081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#182311081">(Dec 02 2019 at 02:31)</a>:</h4>
<p>I, personally, do not! But I understand rlua does quite a bit of longjmp-ing.</p>



<a name="182311530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/longjmp%20interaction%20with%20destructors/near/182311530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pquux <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/longjmp.20interaction.20with.20destructors.html#182311530">(Dec 02 2019 at 02:45)</a>:</h4>
<p>Yeah, my situation is very similar: rust bindings to a C interpreter, rust frame sandwiched between C setjmp and longjmp calls.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>